Code for the Restaurant Management System
Write the object-oriented code to implement the design of the restaurant management system problem.
We've covered different aspects of the restaurant management system and observed the attributes attached to the problem using various UML diagrams. Let us now explore the more practical side of things, where we will work on implementing the restaurant management system using multiple languages. This is usually the last step in an object-oriented design interview process.
We have chosen the following languages to write the skeleton code of the different classes present in the RMS:
Java
C#
Python
C++
JavaScript
Restaurant management system classes#
In this section, we will provide the skeleton code of the classes designed in the class diagram lesson.
Note: For simplicity, we are not defining getter and setter functions. The reader can assume that all class attributes are private and accessed through their respective public getter methods and modified only through their public method functions.
Enumerations and custom data type#
The following code provides the definition of the enumeration and custom data type used in the restaurant management system.
PaymentStatus
: This enumeration keeps track of an order's payment status by the customer.
TableStatus
: This enumeration keeps track of the table’s status.
SeatType
: This enumeration represents the type of seat for a customer.
AccountStatus
: This enumeration keeps track of an account's status.
OrderStatus
: This enumeration keeps the customer's order status in check.
ReservationStatus
: This enumeration represents the reservation status of a table.
Address
: This custom datatype represents the address of the restaurant's branch or a person.
Note: JavaScript does not support enumerations, so we will be using the
Object.freeze()
method as an alternative. This freezes an object and prevents further modifications.
Account and person#
The Account
class represents a user account that has an ID, address, status, and a password that can be reset and is validated using the resetPassword()
function.
The Person
class stores the personal details of a person who can either be an Employee
or a Customer
of the restaurant. The derived class Employee
is further extended by the following:
Receptionist
: Has a method namedcreateReservation()
to create reservations for customersManager
: Has a method namedaddEmployee()
to hire new employees to the restaurantChef
: Has a method namedprepareOrder()
for preparing the orderWaiter
: Has a method namedtakeOrder()
for taking new orders
The derived Customer
class has a private member that stores the last visited date of the customer. The definitions of these classes are provided below:
Table and table seat#
The Table
class has a unique ID. It stores the table status, table location, and maximum capacity. Reservations can be added to a table using the addReservation()
method. It also maintains a list of all the seats it has, where each TableSeat
is identified by a seat number and has a type. The definitions of these classes are provided below:
Meal and meal item#
The MealItem
class is identified by a unique ID and stores and updates the quantity of a menu item. It can be added to a Meal
using the addMealItem()
method, where the Meal
class represents the meal ordered for a specific table. The definitions of these classes are provided below:
Menu, menu section, and menu item#
The Menu
class represents the menu of a restaurant. It is identified by a unique ID and maintains a list of MenuSection
, where the MenuSection
class is the representation of a menu's different sections. A MenuSection
has a list of MenuItem
in which an item's price can be updated. The definitions of these classes are provided below:
Order, kitchen, and reservation#
An Order
has a number of meals and is assigned to a waiter and chef for a specific table. Meals can be updated in an Order
using the addMeal()
and removeMeal()
methods.
A Kitchen
has a number of chefs where new chefs can be assigned using the assignChef()
method.
The Reservation
class represents the reservation of a table that stores the reservation time, people count, status, check-in time, and customer information. It also maintains a list of notifications for the customer.
The definitions of these classes are provided below:
Payment and bill#
The Payment
class is an abstract class with the Check
, CreditCard
, and Cash
classes as its child classes. This takes the PaymentStatus
enum to keep track of the payment status. The Bill
class represents the bill generated for a customer's order. The definitions of these classes are provided below:
Notification#
The Notification
class is another abstract class responsible for sending notifications, with the SmsNotification
and EmailNotification
classes as its child. The implementation of this class is shown below:
Seating chart, branch, and restaurant#
The SeatingChart
class stores the seating plan for a Branch
of the Restaurant
, which can be printed. The Branch
of a restaurant has a specific name, address, and kitchen. The Restaurant
class maintains a list of all the branches under it. The definitions of these classes are provided below:
Wrapping up#
We've explored the complete design of the restaurant management system in this chapter. We've looked at how a basic restaurant management system can be visualized using various UML diagrams and designed using object-oriented principles and design patterns.
Activity Diagram for the Restaurant Management System
Getting Ready: The Facebook System